﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Chaos.view.board
{
    /// <summary>
    /// Interaction logic for board.xaml
    /// </summary>
    public partial class board : UserControl
    {
        private Point m_leftmousedownpos;

        public board()
        {
            InitializeComponent();


            /*
            newContentScale = Math.Min(Math.Max(newContentScale, MinContentScale), MaxContentScale);

            double screenSpaceZoomOffsetX = (contentZoomFocus.X - ContentOffsetX) * ContentScale;
            double screenSpaceZoomOffsetY = (contentZoomFocus.Y - ContentOffsetY) * ContentScale;
            double contentSpaceZoomOffsetX = screenSpaceZoomOffsetX / newContentScale;
            double contentSpaceZoomOffsetY = screenSpaceZoomOffsetY / newContentScale;
            double newContentOffsetX = contentZoomFocus.X - contentSpaceZoomOffsetX;
            double newContentOffsetY = contentZoomFocus.Y - contentSpaceZoomOffsetY;
             * */

           // zoomandpancontrol.ContentScale = zoomandpancontrol.MinContentScale;
           // zoomandpancontrol.ContentOffsetX = newContentOffsetX;
           // zoomandpancontrol.ContentOffsetY = newContentOffsetY;


        }

        private void zoomandpancontrol_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (e.Delta > 0)
            {
                Point p = e.GetPosition(zoomandpancontent);
                zoomin(p);
            }
            else if (e.Delta < 0)
            {
                Point p = e.GetPosition(zoomandpancontent);
                zoomout(p);
            }
            e.Handled = true;
        }

        private void zoomout(Point in_point)
        {
            zoomandpancontrol.ZoomAboutPoint(zoomandpancontrol.ContentScale - 0.1, in_point);
        }

        private void zoomin(Point in_point)
        {
            zoomandpancontrol.ZoomAboutPoint(zoomandpancontrol.ContentScale + 0.1, in_point);
        }

        private void zoomandpancontrol_MouseDown(object sender, MouseButtonEventArgs e)
        {
            m_leftmousedownpos = e.GetPosition(zoomandpancontent);
            zoomandpancontrol.CaptureMouse();
        }

        private void zoomandpancontrol_MouseUp(object sender, MouseButtonEventArgs e)
        {
            zoomandpancontrol.ReleaseMouseCapture();
        }

        private void zoomandpancontrol_MouseMove(object sender, MouseEventArgs e)
        {
            if (zoomandpancontrol.IsMouseCaptured)
            {
                Point p = e.GetPosition(zoomandpancontent);
                Vector dragOffset = p - m_leftmousedownpos;

                zoomandpancontrol.ContentOffsetX -= dragOffset.X;
                zoomandpancontrol.ContentOffsetY -= dragOffset.Y;

            }
        }
    }
}
